package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.AttendGoOutRecordAddDTO;
import org.jsola.hr.dto.AttendGoOutRecordUpdateDTO;
import org.jsola.hr.entity.AttendGoOutRecordDO;
import org.jsola.hr.query.AttendGoOutRecordQuery;
import org.jsola.hr.service.IAttendGoOutRecordService;
import org.jsola.hr.vo.AttendGoOutRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendGoOutRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendGoOutRecordService attendGoOutRecordService;

    /**
     * 生成add测试数据
     * @return AttendGoOutRecordAddDTO
     */
    public AttendGoOutRecordAddDTO getAttendGoOutRecordAddDTO(){
        AttendGoOutRecordAddDTO attendGoOutRecordAddDTO = new AttendGoOutRecordAddDTO();
        attendGoOutRecordAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendGoOutRecordAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendGoOutRecordAddDTO.setDeptId(getRandomValue("varchar",32));
        attendGoOutRecordAddDTO.setDeptName(getRandomValue("varchar",100));
        attendGoOutRecordAddDTO.setEmpInfoId(getRandomValue("varchar",32));
        attendGoOutRecordAddDTO.setEmpInfoName(getRandomValue("varchar",50));
        attendGoOutRecordAddDTO.setYearly(getRandomValue("varchar",10));
        attendGoOutRecordAddDTO.setMonthly(getRandomValue("varchar",10));
        attendGoOutRecordAddDTO.setDaily(getRandomValue("varchar",10));
        attendGoOutRecordAddDTO.setPunchTime(getRandomValue("varchar",10));
        attendGoOutRecordAddDTO.setLongitude(getRandomValue("varchar",100));
        attendGoOutRecordAddDTO.setLatitude(getRandomValue("varchar",100));
        attendGoOutRecordAddDTO.setLocation(getRandomValue("varchar",255));
        attendGoOutRecordAddDTO.setOutInstru(getRandomValue("varchar",255));
        return attendGoOutRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendGoOutRecordUpdateDTO
     */
    public AttendGoOutRecordUpdateDTO getAttendGoOutRecordUpdateDTO(AttendGoOutRecordVO attendGoOutRecordVO){
        return attendGoOutRecordService.selectDOById(attendGoOutRecordVO.getId(), SITE_ID).to(AttendGoOutRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendGoOutRecordQuery
     */
    public AttendGoOutRecordQuery getAttendGoOutRecordQuery() {
        AttendGoOutRecordQuery attendGoOutRecordQuery = new AttendGoOutRecordQuery();
        List<AttendGoOutRecordDO> attendGoOutRecordDOList = attendGoOutRecordService.list(new AttendGoOutRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendGoOutRecordDOList)) {
            AttendGoOutRecordDO attendGoOutRecordDO = attendGoOutRecordDOList.get(0);
            attendGoOutRecordQuery = attendGoOutRecordDO.to(AttendGoOutRecordQuery.class);
            if (attendGoOutRecordDO.getGmtCreate() != null) {
                attendGoOutRecordQuery.setGmtCreateStart(DateKit.getBeforeDay(attendGoOutRecordDO.getGmtCreate(),-1));
                attendGoOutRecordQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendGoOutRecordDO.getGmtCreate(),1));
            }
            if (attendGoOutRecordDO.getGmtModified() != null) {
                attendGoOutRecordQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendGoOutRecordDO.getGmtModified(),-1));
                attendGoOutRecordQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendGoOutRecordDO.getGmtModified(),1));
            }
        }
        return attendGoOutRecordQuery;
    }

    /**
     * 保存示例
     * @return AttendGoOutRecordVO
     */
    public AttendGoOutRecordVO saveAttendGoOutRecordExample(){
        AttendGoOutRecordAddDTO addDTO = this.getAttendGoOutRecordAddDTO();
        AttendGoOutRecordVO attendGoOutRecordVO = attendGoOutRecordService.save(addDTO,buildTokenUser());
        return attendGoOutRecordVO;
    }


}

